package com.huilunyingshi.videoconsumer.controller;

import com.huilunyingshi.videoapi.service.TTvSeriesService;
import com.hullunyingshi.until.ControllerResult;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.ParseException;

@Slf4j
@Scope("prototype")
@RestController
@RequestMapping("/TvS")
public class TvSeriesController {

	private final Logger logger = LoggerFactory.getLogger(AnimeController.class);

	@Autowired
	private TTvSeriesService tTvSeriesService;

    /**
     * 分页查询tv
     * @param keyword
     * @param curPage
     * @return
     * @throws ParseException
     */
	@ApiOperation(value = "分页查询tv列表", notes = "分页查询tv列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "keyword", value = "tv名", paramType = "query", dataType = "String", required = false),
            @ApiImplicitParam(name = "curPage", value = "当前页", paramType = "query", dataType = "int", required = false)
    })
    @GetMapping ("getTvseriesList")
    @ApiResponses(value = {
            @ApiResponse(code = 200, message = "查询成功", response = ControllerResult.class),
            @ApiResponse(code = 400, message = "查询失败", response = String.class),
            @ApiResponse(code = 500, message = "(服务器内部错误)服务器遇到错误，无法完成请求 ", response = String.class),
    })
    public ControllerResult getTvseriesList(String keyword,
                                            Integer curPage
    ) throws ParseException {

        logger.info("#################### TvSeriesController. /TvSeries/getTvseriesList" + keyword + "##" + curPage + "#######");
        try {
            return tTvSeriesService.getTvseriesList(keyword, curPage);
        } catch (Exception e) {
            logger.info("#################### error 500 /TvSeries/getTvseriesList" + e.getStackTrace());
            return new ControllerResult("500", "服务器错误", null);
        }
    }

    @ApiOperation(value = "查询Tv", notes = "查询Tv")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "Tv_id", paramType = "query", dataType = "long", required = false),

    })
    @GetMapping ("getTvseries")
    @ApiResponses(value = {
            @ApiResponse(code = 200, message = "查询成功", response = ControllerResult.class),
            @ApiResponse(code = 400, message = "查询失败", response = String.class),
            @ApiResponse(code = 500, message = "(服务器内部错误)服务器遇到错误，无法完成请求 ", response = String.class),
    })
    public ControllerResult getTvseries(Long id) throws ParseException{
        logger.info("#################### TvseriesController. /Tvseries/getTvseries" + id+"#######");
        try {
            return tTvSeriesService.getTvseries(id);
        } catch (Exception e) {
            logger.info("#################### error 500 /Tvseries/getTvseries" + e.getStackTrace());
            return new ControllerResult("500", "服务器错误", null);
        }

    }

    @ApiOperation(value = "查询类型Tv", notes = "查询类型Tv")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "lid", value = "Tv类型id", paramType = "query", dataType = "long", required = false),
            @ApiImplicitParam(name = "curPage", value = "当前页", paramType = "query", dataType = "int", required = false)
    })
    @GetMapping ("getTvseriesTypeList")
    @ApiResponses(value = {
            @ApiResponse(code = 200, message = "查询成功", response = ControllerResult.class),
            @ApiResponse(code = 400, message = "查询失败", response = String.class),
            @ApiResponse(code = 500, message = "(服务器内部错误)服务器遇到错误，无法完成请求 ", response = String.class),
    })
    public ControllerResult getFilmTypeList(Long lid,  Integer curPage) throws ParseException{
        try {
            return tTvSeriesService.getTvseriesTypeList(lid, curPage);
        }catch (Exception e){
            logger.info("#################### error 500 /Tv/getTvTypeList" + e.getStackTrace());
            return new ControllerResult("500", "服务器错误", null);
        }
    }

}
